package com.qsbc.pygram.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qsbc.pygram.common.Result;
import com.qsbc.pygram.entity.Checkpoint;
import com.qsbc.pygram.entity.MultiQuestion;
import com.qsbc.pygram.service.MultiQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2022-12-30
 */
@RestController
@RequestMapping("/pygram/multi-question")
public class MultiQuestionController {

    @Autowired
    private MultiQuestionService multiQuestionService;


    @GetMapping("{questionId}")
    public Result findOnlyQuestion(
            @PathVariable Integer questionId){
        MultiQuestion multiQuestion = multiQuestionService.getById(questionId);
        return Result.success().success(multiQuestion);
    }

    @DeleteMapping("{questionId}")
    public Result delete(@PathVariable Integer questionId) {
        return Result.success(multiQuestionService.removeById(questionId));
    }


    @PostMapping("/del/batch")
    public Result deleteBatch(@RequestBody List<Integer> questionIds) {
        return Result.success(multiQuestionService.removeByIds(questionIds));
    }



    @PostMapping("/MultiQuestion")
    public Result add(@RequestBody MultiQuestion multiQuestion) {
        int res = multiQuestionService.add(multiQuestion);
        if (res != 0) {

            return Result.success().success(res);
        }
        return Result.error().error();
    }
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestParam(defaultValue = "") String subject,
                           @RequestParam(defaultValue = "") String section,
                           @RequestParam(defaultValue = "") String level) {

        return Result.success(multiQuestionService.findPage(new Page<>(pageNum, pageSize), subject,section,level));
    }

    @PostMapping
    public Result save(@RequestBody MultiQuestion multiQuestion) {
        return Result.success(multiQuestionService.saveOrUpdate(multiQuestion));
    }
}
